package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.FilmBean;
import com.scoy.honeymei.install.GlideImageLoader;
import com.scoy.honeymei.utils.GlideImgUtil;
import com.scoy.honeymei.utils.TimeUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class FilmHomeNewAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<FilmBean> datalist;
    private TextView notv;
    private int type;

    public FilmHomeNewAdapter(Context context, ArrayList<FilmBean> datalist, TextView notv) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
    }

    public FilmHomeNewAdapter(Context context, ArrayList<FilmBean> datalist, int type) {
        this.context = context;
        this.datalist = datalist;
        this.type = type;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_film_home_new, parent, false);
        return new FilmHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        FilmHolder filmHolder = (FilmHolder) holder;
        FilmBean movieBean = datalist.get(position);
        filmHolder.ifhTv.setText(movieBean.getTitle());
        GlideImgUtil.glidePicNo(context, movieBean.getImage(), filmHolder.ifhIv, 10);

        if(position == 0){
            filmHolder.view1.setVisibility(View.VISIBLE);
        }else{
            filmHolder.view1.setVisibility(View.GONE);
        }

        filmHolder.itemView.setOnClickListener(view -> {
            if (onOneClick != null) {
                onOneClick.oneClick(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (type != 1) {
            if (iCount == 0) {
                notv.setVisibility(View.VISIBLE);
            } else {
                notv.setVisibility(View.GONE);
            }
        }
        return iCount;
    }

    class FilmHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ifh_iv)
        ImageView ifhIv;
        @BindView(R.id.ifh_tv)
        TextView ifhTv;
        @BindView(R.id.ifh_buy_tv)
        TextView ifhBuyTv;
        @BindView(R.id.view1)
        View view1;
        @BindView(R.id.view2)
        View view2;



        FilmHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
